home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / mpmod160.zip / SOURCE.ZIP / Z-GEN.C < prev    next >
Text File  |  1994-01-01  |  5KB  |  161 lines

  1. /*---------------------------------------------------------------------------*/
  2. /* This is the main Zmodem program which controls the main general routines. */
  3. /*                                                                           */
  4. /* (C) Copyright M. Jose, 1990 ->                                            */
  5. /* See MPMODEM.DOC for more details about the usage of this source in your   */
  6. /* programs.                                                                 */
  7. /* Written by Mark Jose, Oct-Nov, 1990.                                      */
  8. /*---------------------------------------------------------------------------*/
  9.  
  10. [...]
  11.  
  12. /*
  13.  Read the header (either binary or hex.)
  14. */
  15. int pascal GetHeader(BYTE *hdr)
  16. {
  17. [...]
  18.     switch (c = TimedRead()) {
  19.        case XON:
  20.                goto Again;
  21.        case RCDO:
  22.        case ZTIMEOUT:
  23.                goto Finish;
  24.        case CAN:
  25. gotcancel:
  26.                if (--cancount <= 0)
  27.                    return ZCAN;
  28.                switch((c = GetByte(1))) {
  29.                   case ZTIMEOUT:
  30.                               goto Again;
  31.                   case ZCRCW:
  32.                   case ZCRCW_C:                 /* ---** Add this **--- */
  33.                               switch(GetByte(1)) {
  34.                                  case ZTIMEOUT:
  35.                                              c = ZERROR;
  36.                                              goto Finish;
  37.                                  case RCDO:
  38.                                              return RCDO;
  39.                                  default:
  40.                                              goto Agn2;
  41.                               }     /* Fall through */
  42.                   case RCDO:
  43.                               goto Finish;
  44.                   default:
  45.                               break;
  46.                   case CAN:
  47.                               if (--cancount <= 0)
  48.                                  return ZCAN;
  49.                               goto Again;
  50.                }                /* fallthrough... */
  51.        default:
  52. TryAgain2:
  53. [...]
  54.     Rxframeind = c = TimedRead();
  55.  
  56.     switch (c) {
  57.        case ZBIN:
  58.                RxType = 0;
  59.                c = GetBinaryHeader(hdr);
  60.                break;
  61.        case ZHEX:
  62.                RxType = 0;
  63.                c = GetHexHeader(hdr);
  64.                break;
  65.        case ZBIN32:
  66.                RxType = 1;
  67.                c = GetBinaryHeader32(hdr);
  68.                break;
  69.  
  70. /* There are now two extra indicators - compressed transmission with    */
  71. /* CRC-32 and compression with CRC-16.                                  */
  72.        case ZBINC32:                            /* ---** Add this **--- */
  73.                RxType = 3;                      /* ---** Add this **--- */
  74.                c = GetBinaryHeader32(hdr);      /* ---** Add this **--- */
  75.                break;                           /* ---** Add this **--- */
  76.        case ZBINC:                              /* ---** Add this **--- */
  77.                RxType = 4;                      /* ---** Add this **--- */
  78.                c = GetBinaryHeader(hdr);        /* ---** Add this **--- */
  79.                break;                           /* ---** Add this **--- */
  80. /*  ---- END OF NEW CODE ----  */
  81.  
  82.        case CAN:
  83.                 goto gotcancel;
  84.        case RCDO:
  85.        case ZTIMEOUT:
  86.                 goto AllDone;
  87.        default:
  88.                 goto TryAgain2;
  89.  
  90.     }
  91. [...]
  92. }
  93.  
  94. [...]
  95.  
  96. /*
  97.  Read a byte, checking for ZMODEM escape encoding
  98. */
  99. int pascal GetZDLE()
  100. {
  101.     static int ch;
  102.  
  103. Again:
  104.     if ((ch = GetByte(timeout)) & 0x60)
  105.         return ch;
  106.  
  107.     if (ch != ZDLE)
  108.        if ( ((!UsingFast) && (ch == 17 || ch == 19)) ||  /* ---** Add this **--- */
  109.             (ZCtlEsc && ((ch & 0x60) == 0)) ) {
  110.           goto Again;
  111.        } else
  112.            return ch;
  113.  
  114. Again2:
  115.     if ((ch = GetByte(timeout)) < 0)
  116.        return ch;
  117.     if (ch == CAN && (ch = GetByte(timeout)) < 0)
  118.        return ch;
  119.     if (ch == CAN && (ch = GetByte(timeout)) < 0)
  120.        return ch;
  121.     if (ch == CAN && (ch = GetByte(timeout)) < 0)
  122.        return ch;
  123.     switch (ch) {
  124.        case CAN:
  125.                  return GOTCAN;
  126.        case ZCRCE:
  127.        case ZCRCG:
  128.        case ZCRCQ:
  129.        case ZCRCW:
  130. /* These are compression packets. */
  131.        case ZCRCE_C:         /* ---** Add this **--- */
  132.        case ZCRCG_C:         /* ---** Add this **--- */
  133.        case ZCRCQ_C:         /* ---** Add this **--- */
  134.        case ZCRCW_C:         /* ---** Add this **--- */
  135.                  return(ch|GOTOR);
  136.        case ZRUB0:
  137.                  return 127;     /* return(0177); */
  138.        case ZRUB1:
  139.                  return 255;     /* return(0377); */
  140.        case XOFF:
  141.        case 147:
  142.        case XON:
  143.        case 145:
  144.                  if (!UsingFast)                  /* ---** Add this **--- */
  145.                     goto Again2;
  146.                  else
  147.                     return ch;
  148.        default:
  149.                  if (ZCtlEsc && !(ch & 0x60))
  150.                     goto Again2;
  151.                  if ((ch & 0x60) == 0x40)
  152.                     return (ch ^ 0x40);
  153.                  else if (ch >= 1 && ch <= 31)
  154.                     return ch;
  155.                  break;
  156.     }
  157.     return ZERROR;
  158. }
  159.  
  160. [...]
  161.